local hx__baoshi = fk.CreateSkill {
  name = "hx__baoshi",
}

hx__baoshi:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__baoshi.name) and player.phase == Player.Finish and not player:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
    return player.room:askToSkillInvoke(player, {skill_name = hx__baoshi.name ,prompt = "是否弃置所有手牌对攻击范围内所有角色施加【暴食】？"})
    end
  end,
  on_use = function(self, event, target, player, data)
    local room=player.room
    if event == fk.EventPhaseStart then
      room:throwCard(player:getCardIds(Player.Hand), hx__baoshi.name, player, player)
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if player:inMyAttackRange(p) then
          room:doIndicate(player, {p})
          room:addPlayerMark(p, "@hx__baoshi",1)
        end
      end
    end
  end,
})
hx__baoshi:addEffect(fk.EnterDying, {
  anim_type = "offensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(hx__baoshi.name) and target.hp <= 0 and target:getMark("@hx__baoshi") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local skills = table.filter(target:getSkillNameList(), function (s)
      return not player:hasSkill(s, true)
    end)
    if #skills > 0 then
      local chosen = room:askToChoice(player, {
        choices = skills,
        skill_name = hx__baoshi.name,
        prompt = "#hx__baoshi-choose:" .. target.id,
        detailed = true,
      } )
      if chosen then
        room:handleAddLoseSkills(player, chosen, nil)
        room:doIndicate(player, {target})
        room:sendLog{
          type = "#hx__baoshi_log",
          from = player.id,
          to = {target.id},
          arg = chosen,
        }
      end
    end
    for _, p in ipairs(room.alive_players) do
      room:setPlayerMark(p,"@hx__baoshi", 0)
    end
  end,
})

hx__baoshi:addEffect("prohibit", {
  name = "#hx__baoshi_prohibit",
  is_prohibited = function(self, from, to)
    if from == to or to.general == "hxqunyou__limulu" or to.deputyGeneral == "hxqunyou__limulu" then
      return false
    end
    if from and from:getMark("@hx__baoshi") > 0 then
      return to:getMark("@hx__baoshi") == 0
    end
  end,
})


hx__baoshi:addEffect(fk.Damage, {
  anim_type = "negative",
  global = true,
  priority = 2,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@hx__baoshi") > 0 and player == target
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@hx__nitai_heiyan", 1)
  end,
})
hx__baoshi:addEffect(fk.Damaged, {
  anim_type="negative",
  global = true,
  priority = 2,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@hx__baoshi") > 0 and player == target
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@hx__nitai_heiyan", 1)
  end,
})



return hx__baoshi